package me.frank.tman.ui.analyse;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import me.frank.tman.R;
import me.frank.tman.model.AnalyseModel;
import me.frank.tman.presenter.StockPresenter;

public class AnalyseFragment extends Fragment {

    private static final String TAG = AnalyseFragment.class.getSimpleName();

    private StockPresenter mPresenter = StockPresenter.get();

    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_analyse, container, false);

        TextView totalCapTv = root.findViewById(R.id.tv_analyse_total_cap);
        TextView totalProfitTv = root.findViewById(R.id.tv_analyse_total_profit);
        TextView totalBuyTv = root.findViewById(R.id.tv_analyse_total_buy);
        TextView totalSellTv = root.findViewById(R.id.tv_analyse_total_sell);
        TextView totalBuyFeeTv = root.findViewById(R.id.tv_analyse_total_buy_fee);
        TextView totalSellFeeTv = root.findViewById(R.id.tv_analyse_total_sell_fee);

        AnalyseModel model = mPresenter.getAnalyseResult();

        if (model != null) {
            totalCapTv.setText(String.format("%.3f", model.totalCapitalization));
            totalProfitTv.setText(String.format("%.3f", model.totalProfit));
            totalBuyTv.setText(String.format("%.3f", model.totalBuy));
            totalSellTv.setText(String.format("%.3f", model.totalSell));
            totalBuyFeeTv.setText(String.format("%.3f", model.totalBuyFee));
            totalSellFeeTv.setText(String.format("%.3f", model.totalSellFee));
        }

        return root;
    }
}